using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Globalization;


    public class JavascriptLoader
    {
        public static HtmlGenericControl General(string url)
        {
            if (url == null) throw new ArgumentNullException("url");

            HtmlGenericControl ret = new HtmlGenericControl("script");
            ret.Attributes.Add("type", "text/javascript");
            ret.Attributes.Add("src", url[0] == '~' ? VirtualPathUtility.ToAbsolute(url) : url);
            return ret;
        }
        public static HtmlGenericControl GoogleMaps(string key, string locale)
        {
            return General(String.Format("http://maps.google.com/maps?file=api&sensor=false&hl={0}&key={1}", locale, key));
        }
        public static HtmlGenericControl GoogleMaps(string key, CultureInfo ci)
        {
            return GoogleMaps(key, ci.TwoLetterISOLanguageName);
        }
        public static HtmlGenericControl GoogleMaps(Page page, CultureInfo ci)
        {
            string servername = page.Request.ServerVariables["SERVER_NAME"];
            string key = ConfigurationManager.AppSettings["GMaps-" + servername];
            return GoogleMaps(key, ci.TwoLetterISOLanguageName);
        }
        public static HtmlGenericControl GoogleMapsNew = General("https://maps.google.com/maps/api/js?sensor=false");
        public static HtmlGenericControl GoogleFunctions = General("~/scripts/googleMapsV3.js");
        public static HtmlGenericControl Prototype = General("~/scripts/prototype.js");
        public static HtmlGenericControl PeriodicalExecuter = General("~/scripts/PeriodicalExecuter.js");
        public static HtmlGenericControl Main = General("~/scripts/main.js");
        public static HtmlGenericControl Maps = General("~/scripts/maps.js");
        public static HtmlGenericControl NewMaps = General("~/scripts/googlemaps.js");
        public static HtmlGenericControl CCallWrapper = General("~/scripts/CCallWrapper.js");
        public static HtmlGenericControl Scriptaculous = General("~/scripts/scriptaculous.js");
        public static HtmlGenericControl JQuery = General("~/scripts/jquery/jquery-1.2.6.min.js");
        public static HtmlGenericControl JQuery_Form = General("~/scripts/jquery/jquery.form.js");
        public static HtmlGenericControl JQuery_Timers = General("~/scripts/jquery/jquery.timers.js");
        public static HtmlGenericControl JQuery_UI = General("~/scripts/jquery/jquery-personalized.js");
        public static HtmlGenericControl Alerts = General("~/scripts/jquery.alerts.js");
        public static HtmlGenericControl Menu = General("~/scripts/ddaccordion.js");
        public static HtmlGenericControl Fluidink = General("~/scripts/fluidLayout/ink.js");
        public static HtmlGenericControl sortableList = General("~/scripts/fluidLayout/ink.sortablelist.js");

        public static HtmlGenericControl imagequery = General("~/scripts/fluidLayout/ink.imagequery.js");

        public static HtmlGenericControl autoload = General("~/scripts/fluidLayout/autoload.js");

      /*    <script type="text/javascript" src="scripts/fluidLayout/ink.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.modal.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.sticky.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.toggle.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.progressbar.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.tabs.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.datepicker.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.treeview.js"></script>
    <script type="text/javascript" src="scripts/fluidLayout/ink.imagequery.js"></script>
    
    <script type="text/javascript" src="scripts/fluidLayout/autoload.js"></script>*/

        public class EasyFrota
        {
            public static HtmlGenericControl Main = General("~/Content/JavaScript/easyFrota/Main.js");
            public class Maps
            {
                public static HtmlGenericControl Google = General("~/Content/JavaScript/easyFrota/Maps/Google.js");
            }
        }
        public static void AddAll(Page page)
        {
            page.Header.Controls.Add(Prototype);
            page.Header.Controls.Add(GoogleMaps(page, CultureInfo.CurrentCulture));
            page.Header.Controls.Add(CCallWrapper);
            page.Header.Controls.Add(Main);
            page.Header.Controls.Add(Maps);
            page.Header.Controls.Add(Fluidink);
            page.Header.Controls.Add(sortableList);
            page.Header.Controls.Add(imagequery);
            page.Header.Controls.Add(autoload);

            HtmlGenericControl body = (HtmlGenericControl)page.Master.FindControl("masterBody");
            body.Attributes.Add("onunload", "MainUnload();");
        }
    }

